package com.example.hotelmanagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.hotelmanagement.common.mapper.BaseMapperX;
import com.example.hotelmanagement.common.pojo.PageResult;
import com.example.hotelmanagement.common.query.LambdaQueryWrapperX;
import com.example.hotelmanagement.domain.entity.Guest;
import com.example.hotelmanagement.domain.entity.User;
import com.example.hotelmanagement.domain.vo.GuestPageReqVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
 * 客户表(Guest)表数据库访问层
 *
 * @author makejava
 * @since 2023-06-10 17:32:46
 */
@Mapper
public interface GuestMapper extends BaseMapperX<Guest> {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    Guest queryById(Long id);

    /**
     * 查询指定行数据
     *
     * @param guest 查询条件
     * @param pageable         分页对象
     * @return 对象列表
     */
    List<Guest> queryAllByLimit(Guest guest, @Param("pageable") Pageable pageable);

    /**
     * 统计总行数
     *
     * @param guest 查询条件
     * @return 总行数
     */
    long count(Guest guest);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Guest> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Guest> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Guest> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Guest> entities);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    int deleteById(Long id);

    /**
     * 通过条件查询客户
     * @param guestPageReqVo
     * @return
     */
    default PageResult<Guest> selectPageByCondition(GuestPageReqVo guestPageReqVo){
        return selectPage(guestPageReqVo, new LambdaQueryWrapperX<Guest>()
                .likeIfPresent(Guest::getName, guestPageReqVo.getName())
                .likeIfPresent(Guest::getEmail,guestPageReqVo.getEmail())
                .likeIfPresent(Guest::getIdCard,guestPageReqVo.getIdCard())
                .eqIfPresent(Guest::getGender,guestPageReqVo.getGender())
                .eqIfPresent(Guest::getTel,guestPageReqVo.getTel())
                .eqIfPresent(Guest::getType,guestPageReqVo.getType())
        );
    }
}

